import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useMiddleWare = defineStore('middleware', () => {
  const tid = ref() // 接收到的代理商id
	const SETTID = (id) => {
		tid.value = id
	}
	const latlon = ref({
		latitude: '',
		longitude: '',
		address: ''
	})
	const SETLATLON = (info) => {
		latlon.value = info
	}
	const txInfo = ref({
		bank_code: '', // 银行卡号
		bank_name: '', // 银行卡真实姓名
		bank_site: '', // 开户行地址
		wx_code: '', // 
		wx_img: '',  // 微信收款码id
		wx_name: '', // 微信姓名
		wx_img_path: '', // 微信收款码
		zfb_code: '',  // 
		zfb_img: '',  // 支付宝收款码id
		zfb_name: '',  // 支付宝姓名
		zfb_img_path: '',  // 支付宝收款码
	})
	const SETTXINFO = (info) => {
		txInfo.value = info
	}
  const category = ref([])
  const ptCategory = ref([])
  const setCategory = (type, data) => {
    if(type == 1) ptCategory.value = data
    else category.value = data
  }
	return {
		tid,
		latlon,
		txInfo,
    category,
    ptCategory,
		SETTID,
		SETLATLON,
		SETTXINFO,
    setCategory
	}
}, {
  // 数据持久化
	persist: {
		storage: {
			getItem: (key) => {
			  return uni.getStorageSync(key)
			},
			setItem: (key, value) => {
			  return uni.setStorageSync(key, value)
			},
		}
	}
})
